// 把文件按照二进制进行读取
export function readFile(file) {
  return new Promise(resolve => {
    let reader = new FileReader()
    reader.readAsBinaryString(file) // 将当前文件以二进制的形式读取
    reader.onload = ev => {
      resolve(ev.target.result)
    }
  })
}

// 设置异步间隔延迟
export function delay(interval = 0) {
  return new Promise(resolve => {
    let timer = setTimeout(_ => {
      clearTimeout(timer)
      resolve()
    }, interval)
  })
}

// 字段对应表
export let character = {
  name: {
    text: '姓名',
    type: 'string'
  },
  age: {
    text: '年龄',
    type: 'string'
  }
}

// cookies
export function getCookie(cname) {
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i].trim();
    if (c.indexOf(name) == 0) return c.substring(name.length, c.length).toLocaleLowerCase();
  }
  return "";
}

// 获取组件的样式
export function getStyle(el, prop) {
  return parseInt(window.getComputedStyle(el, null)[prop]);
}

import useWebSocket from "./websocket.js"
export {
  useWebSocket
}